import 'package:flutter/material.dart';
import 'package:flutter_demo_2/counter.dart';
import 'package:flutter_demo_2/shopping_list.dart';
import 'package:flutter_demo_2/spaced_items.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo200',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
        cardTheme: CardTheme(color: Colors.blue.shade50),
        useMaterial3: true,
      ),
      home: Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Title('Counter'),
            Counter(),
            Divider(),
            Title('Shopping List2'),
            ShoppingList(
              products: [
                Product(name: 'Chips'),
                Product(name: 'Milk'),
                Product(name: 'Bread'),
                Product(name: 'Eggs'),
              ],
            ),

            Divider(),
            Title('Spaced Items'),
            Text('SingleChildScrollView and ConstrainedBox'),
            // SpacedItemsList内部使用了minHeight需要一个height限制，
            // 但是此处父节点column并没有设置固定的height，所以使用Expanded。
            Expanded(child: SpacedItemsList()),
          ],
        ),
      ),
    );
  }
}

class Title extends StatelessWidget {
  const Title(this.data, {super.key});
  final String data;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 8),
      child: Text(
        data,
        style: Theme.of(context).textTheme.headlineMedium,
      ),
    );
  }
}
